// components/GlobStepperCard/GlobStepperCard.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        shopdata: {
            type: Object
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        num: 0
    },
    lifetimes: {
        attached: function () {
            // 在组件实例进入页面节点树时执行
            console.log('组件实例化');
            console.log(this.data.shopdata);
        },
        detached: function () {
            // 在组件实例被从页面节点树移除时执行
        },
    },
    /**
     * 组件的方法列表
     */
    methods: {
        Fatherfun(e) {
            console.log(e);
            this.setData({
                num: this.data.shopdata.num
            })
            let enum1 = e.detail.value
            if (Number(e.target.dataset.index)) {
                if (this.data.num < 999) {
                    console.log('小于999走增加');
                    this.setData({
                        num: this.data.num + 1
                    })
                }
            } else if (Number(e.target.dataset.index) == 0) {
                console.log('走减少');
                if ((this.data.num - 1) >= 0) {
                    this.setData({
                        num: this.data.num - 1
                    })
                }
            }
            if (Number(enum1)&&Number(enum1)<=999) {
                console.log('输入触发');
                if (isNaN(e.detail.value) || e.detail.value <= 0) {
                    console.log('走非正数重置');
                    this.setData({
                        num: 0,
                    });
                } else {
                    console.log('输入触发');
                    this.setData({
                        num: Number(e.detail.value),
                    });
                }
            } else if (Number(enum1) == "") {
                console.log('走重置');
                this.setData({
                    num: 0,
                });
            }


            console.log(this.data.num);
            this.triggerEvent('childFun', {
                type: e.target.dataset.index,
                id: this.data.shopdata.id,
                num: this.data.num,
                name: this.data.shopdata.name,
                image: this.data.shopdata.image,
                price: this.data.shopdata.price,
            })
        },
    }
})